package while_lang;

import java.util.*;
import java.io.*;

import java_cup.runtime.Symbol;
import while_lang.ast.*;
import while_lang.parser.ParserCup;
import while_lang.semantics.State;

public class Test {

	public static void main(String[] args) throws Exception {
		System.out.println("Welcome to the While++ interpreter console.");
		System.out.println("Type your code and two enters to evaluate.");
		System.out.println();
		StringBuilder code = new StringBuilder();
		State state = new State();
		Stmt stmt;
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		for (String line = in.readLine(); line != null; line = in.readLine()) {
			if (line.length() > 0) {
				code.append(line +'\n');
			} else if (code.length() > 0) {
				try {
					stmt = ParserCup.parseString(code.toString());
					state = stmt.evaluate(state);
					System.out.println("State: "+ state +"\n");
				} catch (Exception error) {
					System.err.println(error);
				}
				code = new StringBuilder();
			} else {
				System.out.println("Exiting.");
				break; // Exit.
			}		
		}
	}
}
